require_relative "../Expr"

# Expression for assigning value to variables
#
# @author Paul T.
class Calcula::Exprs::AssignExpr < Calcula::Expr

  # @param ident [Calcula::Exprs::IdentExpr]
  # @param value [Calcula::Expr]
  def initialize(ident, value)
    @ident = ident
    @value = value
  end

  # @see Calcula::Expr#to_s
  # @param (see Calcula::Expr#to_s)
  # @return (see Calcula::Expr#to_s)
  def to_s(form: :src)
    identTxt = @ident.to_s(form: form)
    valueTxt = @value.to_s(form: form)
    case form
    when :src then
      "let #{identTxt}=#{valueTxt}"
    when :tree then
      "(let #{identTxt} #{valueTxt})"
    when :ruby then
      "#{identTxt} = #{valueTxt}"
    else
      nil
    end
  end

  # @see Calcula::Expr#children
  # @param (see Calcula::Expr#children)
  # @return (see Calcula::Expr#children)
  def children
    [@ident, @value]
  end
end
